<?php

/* Bootstrap */
require '../application/bootstrap.php';



$response = new Zend_Controller_Response_Http();

try {

    if (isset($_POST['mode']) && $_POST['mode'] == 'synchronous') {

        $responseCode = Pexi_Engine::execute(array('id' => md5(uniqid()), 'message' => $_POST['message']));
        $response->setHttpResponseCode($responseCode);

    } else {

        // Add message to queue
        $db->insert(
            'queue',
            array('message' => $_POST['message'])
        );
        $response->setHttpResponseCode(200);

    }

} catch (Zend_Db_Exception $e) {
    $response->setHttpResponseCode(500);
}

$response->sendResponse();